﻿using Microsoft.ExtendedReflection.Monitoring;
using Microsoft.VisualStudio.TestTools.Execution;
using System;
using System.Collections;

namespace MolesVS2012.Host.Host
{
    internal sealed class SafeContextAccessor : IContextAccessor
    {
        private readonly IContextAccessor contextAccessor;
        private Hashtable _values;

        private Hashtable Values
        {
            get
            {
                if (this._values == null)
                {
                    Hashtable hashtable = new Hashtable();
                    using (_ProtectingThreadContext.Acquire())
                    {
                        IDictionaryEnumerator enumerator = this.contextAccessor.GetEnumerator();
                        while (enumerator.MoveNext())
                            hashtable.Add(enumerator.Key, enumerator.Value);
                    }
                    this._values = hashtable;
                }
                return this._values;
            }
        }

        public int Count
        {
            get
            {
                return this.Values.Count;
            }
        }

        public SafeContextAccessor(IContextAccessor contextAccessor)
        {
            this.contextAccessor = contextAccessor;
        }

        public double GetDoubleValue(string key)
        {
            return (double)this.Values[(object)key];
        }

        public IDictionaryEnumerator GetEnumerator()
        {
            return this.Values.GetEnumerator();
        }

        public int GetIntValue(string key)
        {
            return (int)this.Values[(object)key];
        }

        public object GetObject(string key)
        {
            return this.Values[(object)key];
        }

        public string GetStringValue(string key)
        {
            return (string)this.Values[(object)key];
        }

        public void AddDoubleValue(string key, double value)
        {
            throw new NotImplementedException();
        }

        public void AddIntValue(string key, int value)
        {
            throw new NotImplementedException();
        }

        public void AddObject(string key, object obj)
        {
            throw new NotImplementedException();
        }

        public void AddStringValue(string key, string value)
        {
            throw new NotImplementedException();
        }

        public void RemoveValue(string key)
        {
            throw new NotImplementedException();
        }
    }
}
